package com.mopon.saas.client.thrift;

import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;

import com.mopon.saas.common.thrift.ThriftService;

public class ThriftClient {

	public static void main(String[] args) {
		TProtocol protocol = null;
		try {
			TSocket socket = new TSocket("127.0.0.1", 8089);
			socket.setTimeout(10 * 1000);

			TTransport transport = new TFramedTransport(socket);

			protocol = new TBinaryProtocol(transport);
			transport.open();

			ThriftService.Client client = new ThriftService.Client(protocol);
			client.Service("hello");
		} catch (Exception e) {
			System.out.println("Unable to create thrift client connection");
		} finally {
			if (protocol != null) {//销毁链接
				TTransport transport = protocol.getTransport();
				if (transport.isOpen()) {
					transport.close();
				}
				protocol.reset();
			}
		}
	}
}
